<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .test {
        width: 200px;
        height: 200px;
        background: #666;
      }
    </style>
  </head>
  <body>
    <div class="test"></div>
    <script>
      var dragging = false
      var position = null
      var test = document.getElementsByClassName('test')[0]
      console.log('test----', test.style)

      test.addEventListener('mousedown',function(e){
        console.log('hi222', e.clientX, e.clientY)
        dragging = true
        position = [e.clientX, e.clientY]
      })


      document.addEventListener('mousemove', function(e){
        if(dragging === false) return null
        const x = e.clientX
        const y = e.clientY
        const deltaX = x - position[0]
        const deltaY = y - position[1]
        const left = parseInt(test.style.left || 0)
        const top = parseInt(test.style.top || 0)
        test.style.left = left + deltaX + 'px'
        test.style.top = top + deltaY + 'px'
        position = [x, y]
      })
      document.addEventListener('mouseup', function(e){
        dragging = false
      })
    </script>
  </body>
</html>
